<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" href="../../backstagestatic/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../backstagestatic/admin/css/admin.css" />
	</head>

	<body>
		<form id="form1">
			<input type="hidden" name="">
		</form>
		<div class="page-content-wrap">
				<form class="layui-form" action="">
					<div class="layui-form-item">
						<div class="layui-inline">
							<input type="text" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input">
						</div>
						<div class="layui-inline">
							<select name="category" lay-filter="status">
								<option value="">所有订单</option>
								<option value="010">未付款订单</option>
								<option value="021">已付款订单</option>
								<option value="021">待处理订单</option>
								<option value="021">已退货订单</option>
								<option value="021">未退货订单</option>
							</select>
						</div>
						<button class="layui-btn layui-btn-normal" lay-submit="search">搜索</button>
					</div>
				</form>
				<div class="layui-form" id="table-list">
					<table class="layui-table" id="display"lay-even lay-skin="nob">
						<colgroup>
							<col width="50">
							<col class="hidden-xs" width="50">
							<col class="hidden-xs" width="100">
							<col>
							<col width="80">
							<col width="300">
						</colgroup>
 						<thead>
							<tr>
								<th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
								<th class="hidden-xs">ID</th>
								<th class="hidden-xs">USER</th>
								<th>总价</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<!--<tbody>
							<tr>
								<td><input type="checkbox" name="" lay-skin="primary" data-id="1"></td>
								<td class="hidden-xs">1</td>
								<td class="hidden-xs">1</td>
								<td>100000</td>
								<td><button class="layui-btn layui-btn-mini layui-btn-normal table-list-status" data-status='1'>未付款</button></td>
								<td>
									<div class="layui-inline">
										<button class="layui-btn layui-btn-mini layui-btn-danger " data-id="1" onclick="">同意退款</button>
										<button class="layui-btn layui-btn-mini layui-btn-disabled " disabled="disabled" data-id="1" onclick="">拒绝退款</button>
										<button class="layui-btn layui-btn-mini layui-btn-normal " data-id="1" data-url="order-detail.html"> 查看详情</button>
									</div>
								</td>
							</tr>
							
						</tbody> -->
					</table>
				</div>
		</div>
        <script src="../../js/jquery.min.js"></script>
		<script src="../../backstagestatic/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../backstagestatic/admin/js/common.js" type="text/javascript" charset="utf-8"></script>
		<!-- 未完成 -->
		<script>
			layui.use(['ekement'], function() {
                //修改状态
                $('#agree').click(function() {
                    var That = $(this);
                    var id = That.attr('data-id');
                    var state=That.attr();
                    var data=[];
                    data.push({"id":id, "state":state});
                    $.ajax({
                        type: "POST",//方法类型
                        dataType: "json",//预期服务器返回的数据类
                        url: "/orderState",//url
                        data: JSON.stringify(data),
                        success: function () {
                            alert("修改成功");

                        }
                    });
                    return false;
                });

                $('#refuse').on("click",function() {
                    var That = $(this);
                    var id = That.attr('data-id');
                    var state=That.attr();
                    var data=[];
                    data.push({"id":id, "state":state});
                    $.ajax({
                        type: "POST",//方法类型
                        dataType: "json",//预期服务器返回的数据类
                        url: "/orderState",//url
                        data: JSON.stringify(data),
                        success: function () {
                            alert("修改成功");
                        }
                    });
                    return false;
                });

                $(document).ready(function() {
                    $.ajax({
                        //几个参数需要注意一下
                        type: "POST",//方法类型
                        dataType: "json",//预期服务器返回的数据类
                        url: "/clerk" ,//url
                        data: $('#form1').serialize(),
                        success: function (result) {
                            console.log(result);
                            var Orders=result.orders;
                            console.log(Orders);
                            var str="";
                            str+="<tbody>";
                            for(var i=0;  i < Orders.length; i++){
                                str+="<tr>";
                                str+="<td><input type='checkbox' name='' lay-skin='primary' data-id=  "+i+" ></td>";
                                str+="<td class='hidden-xs'>"+Orders[i].id+"</td>";
                                str+="<td class='hidden-xs'>"+Orders[i].userId+"</td>";
                                str+="<td>"+Orders[i].totalPrice+"</td>";
                                str+="<td><button class='layui-btn layui-btn-mini layui-btn-normal table-list-status' data-status='1'>"+Orders[i].state+"</button></td>";
                                str+="<td><div class='layui-inline'>";
                                //正常订单的话，disable2个按钮
                                if(Orders[i].state=="退货中"){
                                    str+="<button class='layui-btn layui-btn-mini layui-btn-danger' id='agree' data-id='"+Orders[i].id+"' >同意退货</button>";
                                    str+="<button class='layui-btn layui-btn-mini layui-btn-danger' id='refuse' data-id='"+Orders[i].id+" '>拒绝退货</button>";
                                }else{
                                    str+="<button class='layui-btn layui-btn-mini layui-btn-disabled' disabled='disabled'>同意退货</button>";
                                    str+="<button class='layui-btn layui-btn-mini layui-btn-disabled' disabled='disabled'> 拒绝退货</button>";
                                }
                                str+="<button class='layui-btn layui-btn-mini layui-btn-normal' data-id='"+Orders[i].id+"' data-url='order-detail.html'> 查看详情</button>";
                                str+="</div></td>";
                                str+="</tr>";
                            }
                            str+="</tbody>";
                            $("#display").append(str);

                        }
                    });
                    return false;
                });
            });
		</script>
	</body>

</html>